#include "ano_dt.h"

#ifdef __ANO_DT_V8__


uint8_t data_to_send[100];
 
//通过F1帧发送2个uint16类型的数据
void ANO_DT_SendUserInt16Data(uint8_t userCode, int16_t userData[], uint16_t userDataNum)
{
	uint8_t _cnt = 0;
	uint16_t i = 0;
	uint8_t sumcheck = 0;
	uint8_t addcheck = 0;
	int16_t userDataIdx = 0;
	uint16_t flen = userDataNum << 1;

	data_to_send[_cnt++] = 0xAB;//帧头
	data_to_send[_cnt++] = 0x00;//源地址
	data_to_send[_cnt++] = 0xFF;//目标地址
	data_to_send[_cnt++] = userCode;//功能码
	data_to_send[_cnt++] = flen; //数据长度
	data_to_send[_cnt++] = (flen) >> 8;
	//单片机为小端模式-低地址存放低位数据，匿名上位机要求先发低位数据，所以先发低地址
	for(	; userDataIdx < userDataNum; userDataIdx++)
	{
		data_to_send[_cnt++] = BYTE0(userData[userDataIdx]);       
		data_to_send[_cnt++] = BYTE1(userData[userDataIdx]);
	}

	for ( i = 0; i < (flen+6); i++)
	{
		sumcheck += data_to_send[i];//和校验
		addcheck += sumcheck;//附加校验
	}
	data_to_send[_cnt++] = sumcheck;
	data_to_send[_cnt++] = addcheck;

	ANO_DT_Send_Data(data_to_send,_cnt);
	// HAL_UART_Transmit(&huart1,data_to_send,_cnt, 0xffff);
}

#endif // __ANO_DT_V8__
